/*
 * Copyright (c) 2010 Philip Foulkes <philip.foulkes@gmail.com>
 *
 * This file is free software and is made available under the
 * terms of the GNU General Public License, version 2, or at your
 * option, any later version
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/slab.h>
#include <linux/module.h>
#include <linux/hardirq.h>

#include "mrp_private.h"

#include "../include/mrp.h"
#include "../include/mrp_attribute_properties.h"

struct mrp_attribute_properties * mrp_attribute_properties_create_and_init (int attribute_type, void * attribute_value, int attribute_length, int four_packed_type, int new_attribute)
{
	struct mrp_attribute_properties * mrp_attribute_properties;
    
	if (	!(mrp_attribute_properties = kzalloc(sizeof(struct mrp_attribute_properties), MRP_GET_CONTEXT_ALLOC_FLAG))
		||	!(mrp_attribute_properties->attribute_value = kmalloc (attribute_length, MRP_GET_CONTEXT_ALLOC_FLAG)))
	{
		mrp_attribute_properties_destroy (&mrp_attribute_properties);
		return NULL;
	}
    
	mrp_attribute_properties->attribute_type = attribute_type;
	mrp_attribute_properties->four_packed_type = four_packed_type;
	memcpy (mrp_attribute_properties->attribute_value, attribute_value, attribute_length);
	mrp_attribute_properties->new_attribute = new_attribute;

	return mrp_attribute_properties;
}
EXPORT_SYMBOL(mrp_attribute_properties_create_and_init);

void mrp_attribute_properties_destroy (struct mrp_attribute_properties ** mrp_attribute_properties)
{
	struct mrp_attribute_properties * map;

	map = *mrp_attribute_properties;

	if (map)
	{
		kfree (map->attribute_value);
		kfree (map);
		*mrp_attribute_properties = NULL;
	}
}
EXPORT_SYMBOL(mrp_attribute_properties_destroy);

int mrp_attribute_properties_get_attribute_type (struct mrp_attribute_properties * mrp_attribute_properties)
{
	return mrp_attribute_properties->attribute_type;
}
EXPORT_SYMBOL(mrp_attribute_properties_get_attribute_type);

void * mrp_attribute_properties_get_attribute_value (struct mrp_attribute_properties * mrp_attribute_properties)
{
	return mrp_attribute_properties->attribute_value;
}
EXPORT_SYMBOL(mrp_attribute_properties_get_attribute_value);

int mrp_attribute_properties_get_four_packed_type (struct mrp_attribute_properties * mrp_attribute_properties)
{
	return mrp_attribute_properties->four_packed_type;
}
EXPORT_SYMBOL(mrp_attribute_properties_get_four_packed_type);
